
<?php

/*
 Open the connection to the database
*/
$conn = mysql_connect('studentdb.gl.umbc.edu', 'chrimo1', 'chrimo1');
if (!$conn) {
   die('Could not connect');
}

$db_selected = mysql_select_db('chrimo1', $conn);
if (!$db_selected) {
   die ('Can\'t use chrimo1');
}


?>

<html>
<head>
<title>Legacy-Gamer</title>

<link rel="stylesheet" type="text/css" href="legacyGamer.css">

</head>
<body class="body">


<div id="Header" class="style1">
	<div id="sublayer1" >
		<a href="index.php" style="float:left;"><img src="images/Title.png" height="115px" alt="store logo"></a>
		<a href="cart.php" style="float:right; height:115px; border-left:1px solid #ccc; position:relative;">
			<img src="images/cart.png" alt="store logo">

			<?php
				/*
				  Identify the number of items in the cart
				*/
				$sql = "SELECT * FROM shoppingCart WHERE custIdNum='".$_COOKIE['user']."'";
				$result = mysql_query($sql, $conn);
				echo '<h2 style="position: absolute; top:10px">&nbsp &nbsp'.mysql_num_rows($result).'</h2>';

			?>
			
		</a>
		<?php
			echo '<div style="font-size:10pt; color:#FFC80E; float:right;" align="right">Welcome, '.$_COOKIE["user"].'<br>';
			echo '<a href="login.php?logout=1" >Logout</a></div>';
		?>
		
		
	</div>	
</div>
	
<div id="Layer2" class="style2" align="left" >
	<ul id="nav">
	  <h3 style="height:10px; color:#FFC80E;">Genre:</h3>
	  <li2><a href="listItems.php?id=BeatemUp">
 		Beat'em Up
	  </a></li2>
	  <li2><a href="listItems.php?id=RPG">
 		RPG
	  </a></li2>
	  <li2><a href="listItems.php?id=Platform">
 		Platform
	  </a></li2>
	  <li2><a href="listItems.php?id=Action">
 		Action
	  </a></li2>
	  <li2><a href="listItems.php?id=PuzzleStrategy">
 		Puzzle/Strategy
	  </a></li2>
	  <li2><a href="listItems.php?id=ShootemUp">
 		Shoot'em Up
	  </a></li2>
	  <li2><a href="listItems.php?id=CityBuildingSimulator">
 		City Building Simulator
	  </a></li2>
	  <li2><a href="listItems.php?id=ScrollingShooter">
 		Scrollling Shooter
	  </a></li2>
	  <li2><a href="listItems.php?id=Racing">
 		Racing
	  </a></li2>
	  <li2><a href="listItems.php?id=Sports">
 		Sports
	  </a></li2>
	  
	  <h3 style="height:10px; color:#FFC80E;">System:</h3>
	  <li2><a href="listItems.php?id=Sega">
 		Sega Genesis
	  </a></li2>
	  <li2><a href="listItems.php?id=SuperNintendo">
 		Super Nintendo
	  </a></li2>

	  <h3 style="height:10px; color:#FFC80E;">Player Modes:</h3>
	  <li2><a href="listItems.php?id=Single">
 		Single-Player
	  </a></li2>
	  <li2><a href="listItems.php?id=Multi">
 		MultiPlayer
	  </a></li2>
	  <li2><a href="listItems.php?id=Coop">
 		Cooperative
	  </a></li2>

	</ul>
</div>

<div id="Layer3" style="margin-left:5px; margin-top:0px; position:absolute; height:625px; z-index:1; left:175px; top:115px; overflow:inheret; max-width:89%;" align="left"> 
  <form method="get" action="search.php">
    <input style="width:72%;" type="text" name="search">  
    <input type="submit" value="Search">
    <?php 
	$search = $_GET['search'];
	/*
	 Create a query based on the search term used
	*/
	$sql = "SELECT * FROM gameInventory WHERE gameName LIKE '%".$search."%'";

	$result = mysql_query($sql, $conn);
	if (mysql_num_rows($result)==0){
 	  echo '<center><h2 style="color:#FFC80E;">There are no games in the inventory that match your selection</h2></center>';
	  die();
	}
	
	/*
	 List all of the game results in a table with an option to add to cart of view details
	*/
	echo '<table border="0"  style="color:#FFC80E;" >';
	echo '<tr>';
	echo '<th></th><th>Game Name</th><th>Console</th><th align="center">Release Date</th><th align="right">Qty</th><th align="right">Price</th><th min-width="100px" style="min-width:100px;"></th><th></th>';
	echo '</tr>';
	
	while($r = mysql_fetch_array($result))
   	{
         $idNum = $r['idNum'];
         $gameName = $r['gameName'];
         $developer = $r['developer'];
         $releaseDate = $r['releaseDate'];
         $qty = $r['quantity'];
         $price = $r['price'];
	  $image = $r['imageURL'];
	  if($r['system'] == snes){
	    $console = "Super Nintendo";
	  }
	  else{
	    $console = "Sega Genesis";
	  }
	  
         echo '<tr>';
	  echo '<td ><img src="'; echo $image; echo '" height="100px" ></td>';
         echo '<td style="color:#FFC80E;"><a style="color:#FFC80E;" href="showDetails.php?id=';
	  echo $idNum; 
	  echo '">'; 
	  echo $gameName; 
	  echo '</td></a>';
         echo '<td style="color:#FFC80E;">';echo $console;echo '</td>';
         echo '<td align="center" style="color:#FFC80E;">';echo $releaseDate;echo '</td>';
         echo '<td align="right"  style="color:#FFC80E;">'; echo $qty; echo ' </td>';
         echo '<td align="right" style="color:#FFC80E;">$'; echo $price; echo ' </td>';
	  echo '<td align="right" height="35px" width="100px"><a href="cart.php?addId='; echo $idNum; echo'" height="31px" width="91px" class="button">Add to Cart</a></td>';
	  echo '<td>&nbsp; &nbsp;</td>';
         echo '</tr>';
       }
	echo '</table>'

    ?>    

  </form>
</div>

</body>

</html>
